package com.ymatou.iapi.liveseller.testcase;

import java.util.List;
import java.util.Random;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.SysCloseLiveBean;
import com.ymatou.iapi.liveseller.service.SysCloseLiveCall;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.livevideo.parameter.StreamLiveNotifyBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*系统关闭
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SysCloseLive{
	private static SysCloseLiveCall syscloseliveCall;
	private static SysCloseLiveBean syscloseliveBean;
	private static LiveRoomWapper liveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("系统关闭");
	}

	@Before
	public void caseUp() {
		syscloseliveCall=new SysCloseLiveCall();
		syscloseliveBean=new SysCloseLiveBean();
		liveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(syscloseliveCall.getOpurl());
		liveRoomWapper=null;
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SysCloseLive_001() {
		Logger.start(true,"断流状态超出结束时间系统关闭成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			
			StreamLiveNotifyBean streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(createlive.getId(), 0);
			LiveRoomCallService.LiveNotify(streamlivenotifyBean);
			
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextMunite(-100), YMTDateUtil.getBeforeOrNextMunite(-50), createlive.getId());
			syscloseliveCall.setData(syscloseliveBean);
			syscloseliveCall.callService();			
			Logger.verifyEquals("ok", syscloseliveCall.getReturnData(), "验证返回");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			
			Logger.verifyEquals(7, liveroom.getLiveStatus(), "验证系统自动关闭");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SysCloseLive_002() {
		Logger.start(true,"断流状态不超出结束时间系统不关闭");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			
			StreamLiveNotifyBean streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(createlive.getId(), 0);
			LiveRoomCallService.LiveNotify(streamlivenotifyBean);
			
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextMunite(-10), YMTDateUtil.getBeforeOrNextMunite(50), createlive.getId());
			syscloseliveCall.setData(syscloseliveBean);
			syscloseliveCall.callService();			
			Logger.verifyEquals("ok", syscloseliveCall.getReturnData(), "验证返回");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			
			Logger.verifyEquals(3, liveroom.getLiveStatus(), "验证依然在断流状态");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SysCloseLive_003() {
		Logger.start(true,"推流状态超出结束时间系统不关闭");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextMunite(-100), YMTDateUtil.getBeforeOrNextMunite(-50), createlive.getId());
			syscloseliveCall.setData(syscloseliveBean);
			syscloseliveCall.callService();			
			Logger.verifyEquals("ok", syscloseliveCall.getReturnData(), "验证返回");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			
			Logger.verifyEquals(2, liveroom.getLiveStatus(), "验证系统推流");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SysCloseLive_004() {
		Logger.start(true,"8关闭直播不修改状态");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 8);
			syscloseliveCall.callService();			
			syscloseliveCall.setData(syscloseliveBean);
			syscloseliveCall.callService();			
			Logger.verifyEquals("ok", syscloseliveCall.getReturnData(), "验证返回");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			
			Logger.verifyEquals(8, liveroom.getLiveStatus(), "验证系统关闭8");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SysCloseLive_005() {
		Logger.start(true,"9结束直播不修改状态");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 9);
			syscloseliveCall.callService();			
			syscloseliveCall.setData(syscloseliveBean);
			syscloseliveCall.callService();			
			Logger.verifyEquals("ok", syscloseliveCall.getReturnData(), "验证返回");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			
			Logger.verifyEquals(9, liveroom.getLiveStatus(), "验证系统关闭8");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SysCloseLive_006() {
		Logger.start(true,"10强制关停不修改状态");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 10);
			syscloseliveCall.callService();			
			syscloseliveCall.setData(syscloseliveBean);
			syscloseliveCall.callService();			
			Logger.verifyEquals("ok", syscloseliveCall.getReturnData(), "验证返回");
			LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(createlive.getId());
			
			Logger.verifyEquals(10, liveroom.getLiveStatus(), "验证系统关闭8");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}